package com.kehao.leetcode.jzoffer;

import java.util.PriorityQueue;

public class JZSolution059 {

    private static class KthLargest {
        private int k;
        private PriorityQueue<Integer> queue = new PriorityQueue<>();
        public KthLargest(int k, int[] nums) {
            for (int i = 0; i < nums.length; i++) {
                queue.add(nums[i]);
            }
            this.k = k;
            while (queue.size()>k){
                queue.poll();
            }
        }

        public int add(int val) {
            queue.add(val);
            while (queue.size()>k){
                queue.poll();
            }
            return queue.peek();
        }
    }
}
